package com.ruoyi.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BaseFileTableMapper;
import com.ruoyi.system.domain.BaseFileTable;
import com.ruoyi.system.service.IBaseFileTableService;

/**
 * baseFileService业务层处理
 *
 * @author wcc
 * @date 2024-11-26
 */
@Service
public class BaseFileTableServiceImpl implements IBaseFileTableService {
    @Autowired
    private BaseFileTableMapper baseFileTableMapper;

    /**
     * 查询baseFile
     *
     * @param id baseFile主键
     * @return baseFile
     */
    @Override
    public BaseFileTable selectBaseFileTableById(Long id) {
        BaseFileTable data = baseFileTableMapper.selectBaseFileTableById(id);
        List<String> tags = baseFileTableMapper.getTag(id);
        data.setTag(tags);
        return data;
    }

    /**
     * 查询baseFile列表
     *
     * @param baseFileTable baseFile
     * @return baseFile
     */
    @Override
    public List<BaseFileTable> selectBaseFileTableList(BaseFileTable baseFileTable) {
        return baseFileTableMapper.selectBaseFileTableList(baseFileTable);
    }

    /**
     * 新增baseFile
     *
     * @param baseFileTable baseFile
     * @return 结果
     */
    @Override
    public int insertBaseFileTable(BaseFileTable baseFileTable) {
        baseFileTable.setBucket("ruirui");
        String[] names = baseFileTable.getFileName().split("\\.");
        baseFileTable.setFileType(names[names.length - 1]);
        List<String> tags = baseFileTable.getTag();
        baseFileTableMapper.insertBaseFileTable(baseFileTable);
        baseFileTableMapper.deleteTag(baseFileTable.getId());
        for (String tag : tags) {
            baseFileTableMapper.insertTag(baseFileTable.getId(), tag);
        }

        return 1;
    }

    /**
     * 修改baseFile
     *
     * @param baseFileTable baseFile
     * @return 结果
     */
    @Override
    public int updateBaseFileTable(BaseFileTable baseFileTable) {
        return baseFileTableMapper.updateBaseFileTable(baseFileTable);
    }

    /**
     * 批量删除baseFile
     *
     * @param ids 需要删除的baseFile主键
     * @return 结果
     */
    @Override
    public int deleteBaseFileTableByIds(Long[] ids) {
        return baseFileTableMapper.deleteBaseFileTableByIds(ids);
    }

    /**
     * 删除baseFile信息
     *
     * @param id baseFile主键
     * @return 结果
     */
    @Override
    public int deleteBaseFileTableById(Long id) {
        return baseFileTableMapper.deleteBaseFileTableById(id);
    }
}
